#!/bin/bash

set -ex

if [ $# -lt 4 ]; then
  echo "Usage: $0 <TRITON_ASCEND_ROOT> <LLVM_ROOT> <TRITON_ASCEND_VERSION> <BUILD_MODE>"
  exit 1
fi

TRITON_ASCEND_ROOT=$1
LLVM_ROOT=$2
TRITON_ASCEND_VERSION=$3
BUILD_MODE=$4

TRITON_ASCEND_PROJECT_ROOT=$(readlink -f "${TRITON_ASCEND_ROOT}/..")

cd $TRITON_ASCEND_PROJECT_ROOT

LLVM_SYSPATH=${LLVM_ROOT} \
TRITON_PLUGIN_DIRS=${TRITON_ASCEND_ROOT} \
TRITON_BUILD_WITH_CCACHE=true \
TRITON_BUILD_WITH_CLANG_LLD=true \
TRITON_BUILD_PROTON=OFF \
TRITON_WHEEL_NAME="triton_ascend" \
TRITON_VERSION=${TRITON_ASCEND_VERSION} \
TRITON_APPEND_CMAKE_ARGS="-DTRITON_BUILD_UT=OFF" \
python3 setup.py ${BUILD_MODE}
